<?php

namespace App\Services\Search;

use App\Models\Car;
use App\Models\House;
use App\Models\Pet;
use App\Models\Used;
use Illuminate\Support\Arr;

/**
 * 全局搜索服务
 * @package App\Services
 */
class SearchService
{
    //获取顶部搜索内容
    public function generate(string $word)
    {
        $houses = House::word($word);
//        $cars = Car::select('article_id', 'id', 'title')->where('title', 'like', '%' . $word . '%')->limit(1);
//        $useds = Used::select('article_id', 'id', 'title')->where('title', 'like', '%' . $word . '%')->limit(1);
//        $pets = Pet::select('article_id', 'id', 'title')->where('title', 'like', '%' . $word . '%')->limit(1);
        return $houses;
    }

//默认数据
    public function defaultData()
    {
        $res = [];
        $houses = House::all();
//        $houses = collect(House::load('article.title')->all(['id', 'article_id', 'title']));
//        $cars = collect(Car::all(['id', 'article_id', 'title'])->load('article.title'));
//        $useds = collect(Used::all(['id', 'article_id', 'title'])->load('article.title'));
//        $pets = collect(Pet::all(['id', 'article_id', 'title'])->load('article.title'));
//        $res = $houses->concat($cars)->concat($useds)->concat($pets);
        return $houses;
        return $res;
    }
}
